
import SelectAppList from '@/components/select-app-list';

export default {
    name: 'repay-data',
    components: {
        SelectAppList
    },
    data() {
        const today = new Date();
        today.setHours(0, 0, 0, 0);
        return {
            form: {
                date: '',
                userType: [],
                appName: []
            },
            dataTotal: {},
            rules: {},
            tableData: [],
            tableMaxHeight: 500,
            pickerOptions: {
                disabledDate(date) {
                    return date.getTime() >= today.getTime();
                },
            },
        };
    },
    methods: {
        // 获取列表数据
        getTableData() {
            if(!this.form.date) {
                this.$message.warning(this.$tc('verify.plsChooseDate'));
                return;
            }
            const params = this.fillParams();
            this.tableData = [];
            this.$api.report.queryFinreportContractCollectionByDisburse(params).then(res => {
                const {status, data, error} = res;
                if ('1' === status && '00000000' === error && data) {
                    this.tableData = data.finreportContractCollectionByDisburseWithBLOBs || [];
                    const { dueContractSum, s1OverdueSum, s1OverdueRateSum, s1PaidSum, s1PaidRateSum, s2OverdueSum, s2OverdueRateSum, s2PaidSum, s2PaidRateSum, s3OverdueSum, s3OverdueRateSum, s3PaidSum, s3PaidRateSum, inOverdueContractSum, inOverdueContractRateSum } = data;
                    this.dataTotal = { dueContractSum, s1OverdueSum, s1OverdueRateSum, s1PaidSum, s1PaidRateSum, s2OverdueSum, s2OverdueRateSum, s2PaidSum, s2PaidRateSum, s3OverdueSum, s3OverdueRateSum, s3PaidSum, s3PaidRateSum, inOverdueContractSum, inOverdueContractRateSum };
                }
                this.tableMaxHeight = document.body.clientHeight - 165;
            });
        },
        // 配置查询和导出参数
        fillParams() {
            const form = this.form;
            const params = {
                userTypes: form.userType,
                appNames: form.appName,
                dueDateStart: '',
                dueDateEnd: '',
            };
            if (form.date) {
                params.dueDateStart = form.date[0];
                params.dueDateEnd = form.date[1];
            }
            return params;
        },
        exportExcel() {
            if(!this.form.date) {
                this.$message.warning(this.$tc('verify.plsChooseDate'));
                return;
            }
            const params = this.fillParams();
            const user = this.$storage.get("user");
            params.language = this.$storage.getLocal('language');
            params.token = user.token;
            const {$apiConf} = this;
            const url = this.$urlUtil.fillParams(params, $apiConf.baseUrl + $apiConf.urlType.report.finreportContractCollectionByDisburseExport, ["page"]);
            this.$openNewBlank(url);
        },
        toPercent(point){
            if (!point) {
                return '0%';
            }
            let str = Number(point * 100).toFixed(2);
            str += "%";
            return str;
        },
        // 总计数据
        getSummaries(param) {
            const { columns } = param;
            const sums = [];
            const { dueContractSum, s1OverdueSum, s1OverdueRateSum, s1PaidSum, s1PaidRateSum, s2OverdueSum, s2OverdueRateSum, s2PaidSum, s2PaidRateSum, s3OverdueSum, s3OverdueRateSum, s3PaidSum, s3PaidRateSum, inOverdueContractSum, inOverdueContractRateSum } = this.dataTotal;
            const formatCurrency = this.$options.filters.formatCurrency;
            columns.forEach((item,index)=> {
                if (index === 0) {
                    sums[index] = this.$t('common.totals');
                    return;
                }
                switch (item.property) {
                    case 'dueContract':
                        sums[index] = formatCurrency(dueContractSum);
                        break;
                    case 's1Overdue':
                        sums[index] = formatCurrency(s1OverdueSum);
                        break;
                    case 's1OverdueRate':
                        sums[index] = s1OverdueRateSum;
                        break;
                    case 's1Paid':
                        sums[index] = formatCurrency(s1PaidSum);
                        break;
                    case 's1PaidRate':
                        sums[index] = s1PaidRateSum;
                        break;
                    case 's2Overdue':
                        sums[index] = formatCurrency(s2OverdueSum);
                        break;
                    case 's2OverdueRate':
                        sums[index] = s2OverdueRateSum;
                        break;
                    case 's2Paid':
                        sums[index] = formatCurrency(s2PaidSum);
                        break;
                    case 's2PaidRate':
                        sums[index] = s2PaidRateSum;
                        break;
                    case 's3Overdue':
                        sums[index] = formatCurrency(s3OverdueSum);
                        break;
                    case 's3OverdueRate':
                        sums[index] = s3OverdueRateSum;
                        break;
                    case 's3Paid':
                        sums[index] = formatCurrency(s3PaidSum);
                        break;
                    case 's3PaidRate':
                        sums[index] = s3PaidRateSum;
                        break;
                    case 'inOverdueContract':
                        sums[index] = formatCurrency(inOverdueContractSum);
                        break;
                    case 'inOverdueContractRate':
                        sums[index] = inOverdueContractRateSum
                        break;
                    default:
                        break;
                }
            })
            return sums;
        }
    },
    created() {
        // this.getTableData();
    },
};
